<?php

/**
 * DataMore数据接口
 * Date: 2018/11/21
 * Time: 17:01
 */

namespace Lib\Paas;

use Lib\Base\Common;

class DataMore extends Base
{
    public function __construct($sData = [])
    {
        parent::__construct($sData);
    }

    /**
     * 查询经分接口数据
     *
     * @param int $dmId【必填】 活动数据ID
     * @param string $dmCmd【必填】 经分接口命令串 如："/dmfeature/598/getplayerlastlogin/openid=<sGameOpenId>"
     * @return array
     * [
     *      'iRet' => '=0 请求成功，!=0 请求失败',
     *      'sMsg' => '',
     *      'data' => [接口数据，具体信息参考接口文档],
     *      'datas' => [接口数据，具体信息参考接口文档],
     * ]
     */
    public function getData($dmId, $dmCmd)
    {
        //私有参数
        $paasParam = [
            'acctype' => Common::getAcctype(),
            'dmId' => $dmId,
        ];

        //组合URL
        $url = $this->getPaasRequestUrl('gameattr.sdatamore', $paasParam);
        $res = $this->http->post($url, $dmCmd);
        recordLog('查询自定义接口返回值：' . var_export($res, true), __FILE__, __LINE__);

        if ($res['ret'] != 0) {
            $this->tglogReport('框架请求ULink-Paas出现异常，curl_errno：' . $res['ret'] . '，curl_error：' . $res['msg'], 'gameattr.sdatamore');
            return $this->getRetData(CURL_ERROR_NO, '系统繁忙，请稍后再试！');
        }
        $res = $res['data'];
        if ($res['ret'] != 0 || $res['data']['ret'] != 0) {
            $iRet = $res['ret'] != 0 ? $res['ret'] : $res['data']['ret'];
            return $this->getRetData($iRet, '系统繁忙，请稍后再试！');
        } else {
            $res = $res['data']['data']; //经分接口返回的数据
            if ($res['code'] != 0) {
                return $this->getRetData($res['code'], '系统繁忙，请稍后再试！');
            } else {
                unset($res['code'], $res['HttpStatus'], $res['message']);
                return $this->getRetData(0, 'success', $res);
            }
        }
    }
}
